package com.austin.leetcode.algorithm.LeetCodeArray;

/**
 * @author Linbizhao
 * @description: 要求删除数组中等于 val 的元素，因此输出数组的长度一定小于等于输入数组的长度
 * @leetcode: https://leetcode.cn/problems/remove-element/description/?envType=study-plan-v2&envId=top-interview-150
 * @since 2024/1/10 15:58
 */
class SolutionRemoveElement {

    public int removeElement(int[] nums, int val) {
        int len = nums.length;
        int left  = 0;
        for (int right = 0; right < len; right++) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                left ++;
            }
        }
        return left;
    }
}
